package com.xhs.core.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

/**
 * @desc: mybatis-Flex全局配置
 * @projectName: spring-boot3-demo
 * @author: xhs
 * @date: 2025-06-10 周二 10:58
 */
@Slf4j
@Configuration
public class MyBatisFlexConfig  implements MyBatisFlexCustomizer {

    @Resource
    private ConsoleMessageCollector consoleMessageCollector;
    @Resource
    private ConsoleMessageReporter consoleMessageReporter;

    @Override
    public void customize(FlexGlobalConfig flexGlobalConfig) {
        // 注册全局数据填充监听器
//        flexGlobalConfig.registerInsertListener(new EntityListener(), BaseEntity.class);
//        flexGlobalConfig.registerUpdateListener(new EntityListener(), BaseEntity.class);
//
//        // 全局配置逻辑删除字段
//        flexGlobalConfig.setLogicDeleteColumn("is_deleted");

        // 开启审计功能
        AuditManager.setAuditEnable(true);

        // 设置SQL审计收集器
        AuditManager.setMessageReporter(consoleMessageReporter);

        // 设置SQL输出到控制台
        AuditManager.setMessageCollector(consoleMessageCollector);
    }
}
